import z from "zod";

export const createWishSchema = z.object({
  dishesId: z
    .number()
    .int("dishesId必须是整数")
    .positive("dishesId必须是正整数"),
});

export type CreateWishSchema = z.infer<typeof createWishSchema>;

export const deleteWishSchema = z.object({
  userId: z
    .string()
    .refine(
      // 验证是否可以转换为整数
      (val) => {
        const num = parseInt(val, 10);
        return !isNaN(num) && Number.isInteger(num) && num.toString() === val;
      },
      { message: "userId必须是有效的整数" }
    )
    // 转换为整数类型
    .transform((val) => parseInt(val, 10)),
  dishesId: z
    .string()
    .refine(
      // 验证是否可以转换为整数
      (val) => {
        const num = parseInt(val, 10);
        return !isNaN(num) && Number.isInteger(num) && num.toString() === val;
      },
      { message: "userId必须是有效的整数" }
    )
    // 转换为整数类型
    .transform((val) => parseInt(val, 10)),
});

export type DeleteWishSchema = z.infer<typeof deleteWishSchema>;
